package thread.lock;

import java.util.concurrent.atomic.AtomicReference;

public class SpinLock {
     AtomicReference<Thread> atomicReference = new AtomicReference<>();
     
     public void myLock(){
         Thread thread = Thread.currentThread();
         System.out.println(Thread.currentThread().getName() + "---> myLock");
         
         while (!atomicReference.compareAndSet(null,thread)){
             
         }
     }

    public void myUnLock(){
        Thread thread = Thread.currentThread();
        System.out.println(Thread.currentThread().getName() + "---> myUnLock");

        atomicReference.compareAndSet(thread,null);

    }
}
